package com.sinothk.android.utils.demo.net;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.sinothk.android.utils.XUtils;

import java.util.Objects;

public class NetChangeReceiver extends BroadcastReceiver {

    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equalsIgnoreCase("android.net.conn.CONNECTIVITY_CHANGE")) {
            if (XUtils.net().isConnected()) {
                //有网处理
                XUtils.toast().show("有网");
                Log.e("NetChangeReceiver", "有网");
            } else {
                //无网显示个提示什么的
                XUtils.toast().show("异常");
                Log.e("NetChangeReceiver", "断网");
            }
        }
    }

    public static boolean equalsObj(Object a, Object b) {
        return Objects.equals(a, b);
    }
}